# -*- coding: utf-8 -*-
"""
Created on Mon Jun 10 14:11:47 2019

@author: Administrator
"""
# 1031 检查身份证
# 思路：获取输入的前17位后加权求和的结果，与输入的最后一位比较判断是否相同
# 注意：注意前17可以包含字符

# 只检查前17位是否全为数字且最后1位校验码计算准确

# 测试用例：
# 1输入要求N<=100，如果N=0如何解决
# 2如果输入数据中有字符，则输出为异常身份证号

def test():
    num = int(input())
    
    # 保持原始数据
    raw_list = []
    
    # 记录错误身份证号个数
    count = 0
    for i in range(num):
        raw = input()
        raw_list.append(raw)
        
    for j in range(num):
        
        raw = raw_list[j]
        # 获取前17位 和校验位
        input_data = raw[0:17]
        check = raw[len(raw)-1]
        
        sum_result = weighted_sum(input_data)
        
        # 如果17不全为数字
        if sum_result == -1:
            print(raw)
            continue
        
        result = sum_result % 11
        
        # 如果校验不匹配
        if mapping(result) != check:
            print(raw)
            count = count + 1
        
    if count == 0:
        print('All passed')

def weighted_sum(str_data):
    result = 0
    weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
    length = len(str_data)
    
    for i in range(length):
        if not str(str_data[i]).isdigit():
            return -1
        
        result += int(str_data[i]) * weight[i]
        
    return result


def mapping(num_data):
    result = ''
    
    if num_data == 0:
        result += '1'
    elif num_data == 1:
        result += '0'
    elif num_data == 2:
        result += 'X'
    elif num_data == 3:
        result += '9'
    elif num_data == 4:
        result += '8'
    elif num_data == 5:
        result += '7'
    elif num_data == 6:
        result += '6'
    elif num_data == 7:
        result += '5'
    elif num_data == 8:
        result += '4'
    elif num_data == 9:
        result += '3'
    elif num_data == 10:
        result += '2'
    
    return result
    
test()
s